/*********************************************************************************
  *Copyright (C), 2016-2022, zhangjiance Tech. Co., Ltd.
  *FileName:  download_common.h
  *Author:  JianCe.Zhang
  *Version:  V1.0
  *Date: 2023-06-14
  *Description: 
  *Function List:
  * 1. void function(void)
  * 2. 
  * 3. 
  * 4. 
  *History:
  * 1. 2022.8.28;JianCe.Zhang;Init Function 
  * 2. 
  * 3. 
  * 4. 
**********************************************************************************/

#ifndef  __download_common_H__
#define  __download_common_H__


/***************************************Includes***********************************/
#include <string>
#include <future>
#include <functional>
#include "thread_task_common.h"

/***************************************Macros***********************************/


/***************************************Variables***********************************/



/***************************************Functions***********************************/

namespace zhangjiance
{
namespace upgradeservice
{

  enum class DownloadStatus:int
  {
    Init = 0,
    Downloading = 1,
    Paused = 2,
    Canceled = 3,
    Completed = 4,
    Failed = 5
  };

  class DownloadTask
  {
  public:
    virtual ~DownloadTask() noexcept {}
    virtual bool init() = 0;
    virtual bool download() = 0;
    virtual bool pause() = 0;
    virtual bool resume() = 0;
    virtual bool cancel() = 0;
    virtual DownloadStatus getStatus() = 0;
    virtual std::string getDownloadUrl() = 0;
    virtual std::string getDownloadPath() = 0;
    virtual long long getDownloadedSize() = 0;
    virtual long long getFileSize() = 0;
    virtual int getProgress() = 0;
    virtual void setDownloadUrl(const std::string& url) = 0;
    virtual void setDownloadPath(const std::string& path) = 0;
    virtual void setOptions(std::function<void(int,DownloadStatus)> callback,long speedLimit, int connecttimeout,int downloadtimeout) = 0;
    

protected:
    std::string m_downloadUrl="";
    std::string m_downloadPath="";
    long m_downloadSpeedLimit=0;
    long m_downloadTimeout=0;
    long m_connectTimeout=0;
    long long m_downloadedSize=0;
    long long m_fileSize=0;
    long long m_FsyncSize=0;
    long long m_resumeFrom=0;
    std::function<void(int,DownloadStatus)> m_downloadCallback=nullptr;
    bool m_isFsyncEnabled=true;
    int m_downloadProgress=0;
    DownloadStatus m_downloadStatus=DownloadStatus::Init;
    DownloadTask& operator=(const DownloadTask&) = delete;
};

}
}

#endif
/* [] END OF download_common.h */